package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_8_13_Training {
    //珠玑妙算
    public int[] masterMind(String solution, String guess) {
        int[][] hash = new int[26][2];
        int[] ans = new int[2];
        var s = solution.toCharArray();
        var g = guess.toCharArray();

        for (int i = 0; i < 4; i++) {
            if (s[i] == g[i]) {
                ans[0]++;
            } else {
                hash[s[i] - 'A'][0]++;
                hash[g[i] - 'A'][1]++;
            }
        }

        for (int[] arr : hash) {
            ans[1] += arr[0] > arr[1] ? arr[1] : arr[0];
        }

        return ans;
    }
}
